package com.tanhua.controller;

import com.tanhua.domain.mongo.QuestionList;
import com.tanhua.domain.mongo.QuestionOption;
import com.tanhua.service.SoulQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 题和选项
 * TODO：题的增删改查     选项的增删改查
 *
 * @author user
 */
@RestController
@CrossOrigin
@RequestMapping("/soulquest")
public class SoulQuestionController {
    @Autowired
    public SoulQuestionService soulQuestionService;

    /**
     * 根据试卷id查询题的id，然后查询题
     */
    @GetMapping("/getSoulQuestionById")
    public ResponseEntity getSoulQuestionById(Integer souId) {
        return soulQuestionService.getSoulQuestionById(souId);
    }


    /**
     * 根据id删除题
     * * 试卷id和
     * * 题的id
     *
     * @param soulId     试卷id
     * @param questionId 题的id
     * @return
     */
    @GetMapping("/deleteQuestionById/{soulId}/{questionId}")
    public ResponseEntity deleteQuestionById(@PathVariable("soulId") String soulId, @PathVariable("questionId") String questionId) {
        return soulQuestionService.deleteQuestionById(Integer.parseInt(soulId), Integer.parseInt(questionId));
    }


    /**
     * 修改题
     *
     * @return
     */
    @PostMapping("/updateQuestion")
    public ResponseEntity updateQuestion(@RequestBody QuestionList questionList) {
        return soulQuestionService.updateQuestion(questionList);
    }

    /**
     * 添加题
     *
     * @return soulId :试卷id
     */
    @PostMapping("/addQuestion/{soulId}")
    public ResponseEntity addQuestion(@PathVariable("soulId") Integer soulId, @RequestBody QuestionList questionList) {
        return soulQuestionService.addQuestion(soulId, questionList);
    }


    /**
     * 查询选项
     *
     * @return
     */
    @GetMapping("/queryOptions")
    public ResponseEntity queryOptions(Integer questionId) {
        return soulQuestionService.queryOptions(questionId);
    }


    /**
     * 删除选项
     *
     * @param questionId
     * @param optionId
     * @return
     */
    @GetMapping("/deleteOption/{questionId}/{optionId}")
    public ResponseEntity deleteOption(@PathVariable("questionId") String questionId, @PathVariable("optionId") String optionId) {
        return soulQuestionService.deleteOption(Integer.parseInt(questionId), Integer.parseInt(optionId));
    }

    /**
     * 修改选项
     *
     * @return
     */
    @PostMapping("/updateOption/{questionId}")
    public ResponseEntity updateOption(@PathVariable("questionId") Integer questionId, @RequestBody QuestionOption questionOption) {
        return soulQuestionService.updateOption(questionId, questionOption);
    }


    /**
     * 添加选项
     *
     * @param questionId
     * @param questionOption
     * @return
     */
    @PostMapping("/addOption/{questionId}")
    public ResponseEntity addOption(@PathVariable("questionId") Integer questionId, @RequestBody QuestionOption questionOption) {
        return soulQuestionService.addOption(questionId, questionOption);
    }

    /**
     * 根据id查询单个题
     *
     * @param questionId
     * @return
     */
    @GetMapping("/getQuestionById/{questionId}")
    public ResponseEntity getQuestionById(@PathVariable("questionId") String questionId) {
        return soulQuestionService.getQuestionById(questionId);
    }

    /**
     * 根据id查询单个选项
     *
     * @param questionId
     * @return
     */
    @GetMapping("/getQuestionOptionById/{option}/{questionId}")
    public ResponseEntity getQuestionOptionById(@PathVariable("option") String option, @PathVariable("questionId") String questionId) {
        return soulQuestionService.getQuestionOptionById(option, questionId);
    }


}
